﻿<Common:LayoutAwarePage
    x:Class="Looptribe.Moodlin8.View.LoginPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Looptribe.Moodlin8.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="Looptribe.WinRT.Toolkit" xmlns:Toolkit="using:Looptribe.WinRT.Toolkit"
    xmlns:Common="using:Looptribe.Moodlin8.Common" mc:Ignorable="d"
    DataContext="{Binding Login, Source={StaticResource Locator}}">

    <Page.Transitions>
        <TransitionCollection>
            <ContentThemeTransition />
        </TransitionCollection>
    </Page.Transitions>

    <Page.Resources>
        <Style x:Key="SignInPageStyle" TargetType="Grid">
            <Setter Property="Background" Value="{StaticResource MoodleOrangeColor}"/>
            <Setter Property="ChildrenTransitions">
                <Setter.Value>
                    <TransitionCollection>
                        <ContentThemeTransition></ContentThemeTransition>
                    </TransitionCollection>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource SignInPageStyle}">
        <Grid Background="{StaticResource MoodleOrangeColor}">
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Image Source="ms-appx:///Assets/Moodle_Logo_Splash.png" Width="400" VerticalAlignment="Bottom"/>
            </Grid>
            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>
                <StackPanel DataContext="{Binding Credentials}" Grid.Row="0">
                    <TextBlock Width="220" Margin="30,20,0,0" Text="Username" HorizontalAlignment="Center" FontSize="16" Foreground="White" />
                    <TextBox Width="220" Margin="30,5,0,0" Background="#FFA74324" HorizontalAlignment="Center" FontSize="16" Foreground="White" BorderThickness="1"
                        Text="{Binding Username}"
                        Toolkit:UpdateSourceHelper.IsEnabled="True"
                        Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding Username, Mode=TwoWay}"/>
                    <TextBlock Width="220" Margin="30,20,0,0" Text="Password" HorizontalAlignment="Center" FontSize="16" Foreground="White" />
                    <PasswordBox x:Name="_passwordBox" Width="220" Margin="30,5,0,0" Background="#FFA74324" HorizontalAlignment="Center" Foreground="White" BorderThickness="1" />
                    <TextBlock Width="220" Margin="30,20,0,0" Text="URL (eg. http://www.edwi.it/)" HorizontalAlignment="Center" FontSize="16" Foreground="White" />
                    <TextBox x:Name="_baseUri" Width="220" Margin="30,5,0,0" Background="#FFA74324" HorizontalAlignment="Center" Foreground="White" BorderThickness="1"    
                        Text="{Binding BaseUri}"
                        Toolkit:UpdateSourceHelper.IsEnabled="True" 
                        Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding BaseUri, Mode=TwoWay}" />
                    <!--<TextBox Width="220" Margin="30,20,0,0" Background="#FFA74324" HorizontalAlignment="Center" Foreground="White" BorderThickness="1"    
                        Text="{Binding ServiceName}" 
                        Toolkit:UpdateSourceHelper.IsEnabled="True" 
                        Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding ServiceName, Mode=TwoWay}" />-->
                </StackPanel>
                <Button Grid.Row="1" Width="226" Content="LOG IN" Margin="30,20,0,0" HorizontalAlignment="Center" Background="White" Foreground="{StaticResource MoodleOrangeColor}"
                    Click="LoginClick" />
                <ProgressBar IsIndeterminate="True" Visibility="{Binding IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}" />
            </Grid>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>

    <!--<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="180"/>
        </Grid.RowDefinitions>
        <Canvas Grid.Row="0">
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
        </Canvas>
        <StackPanel HorizontalAlignment="Center" Grid.Row="1">
            <StackPanel HorizontalAlignment="Center" DataContext="{Binding Credentials}">
                <TextBox Text="{Binding Username}" 
                     Toolkit:UpdateSourceHelper.IsEnabled="True" 
                     Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding Username, Mode=TwoWay}" />
                <TextBox Text="{Binding Password}" 
                     Toolkit:UpdateSourceHelper.IsEnabled="True" 
                     Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding Password, Mode=TwoWay}" />
                <TextBox Text="{Binding BaseUri}" 
                     Toolkit:UpdateSourceHelper.IsEnabled="True" 
                     Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding BaseUri, Mode=TwoWay}" />
                <TextBox Text="{Binding ServiceName}" 
                     Toolkit:UpdateSourceHelper.IsEnabled="True" 
                     Toolkit:UpdateSourceHelper.UpdateSourceText="{Binding ServiceName, Mode=TwoWay}" />
            </StackPanel>
            <Button Content="Login" Command="{Binding LoginCommand}" />
        </StackPanel>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>-->
</Common:LayoutAwarePage>